
package com.hualan.sfzy.service.psyc.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.hualan.sfzy.entity.Question;

import com.hualan.sfzy.mapper.psyc.QuestionMapper;
import com.hualan.sfzy.service.psyc.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class QuestionServiceImpl implements QuestionService {
    @Autowired
   private QuestionMapper questionMapper;
    public QuestionServiceImpl(QuestionMapper  questionMapper) {
        this.questionMapper = questionMapper;
    }
    @Override
    public int add(Question question) {
        return questionMapper.insert(question);
    }

    @Override
    public int removeById(Integer id) {
        return questionMapper.delete(id);
    }

    @Override
    public int remove(Integer[] ids) {
        return questionMapper.deleteBatch(ids);
    }

    @Override
    public int edit(Question question) {
        return questionMapper.update(question);
    }

    @Override
    public Question findById(Integer id) {
        return questionMapper.selectById(id);
    }

    @Override
    public List<Question> find() {
        return questionMapper.select(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pangNum, Integer pageSize, Question question) {
        PageHelper.startPage(pangNum,pageSize);
        List<Question> list= questionMapper.select(question);
        PageInfo<Question>  pageInfo=new PageInfo<>(list);
        Map<String,Object> map=new HashMap<>();
        map.put("list",list);
        map.put("total",pageInfo.getTotal());
        map.put("pages",pageInfo.getPages());

        return map;
    }
}
